package com.icehand.payment.pay;

import com.icehand.common.enums.PayChannelEnum;
import com.icehand.payment.model.NotifyWrapper;
import com.icehand.payment.model.PayWrapper;

import java.util.List;

/**
 * @author icehand
 */
public class PayTemplate implements Pay {
    private final List<Pay> list;

    public PayTemplate(List<Pay> list) {
        this.list = list;
    }

    @Override
    public void pay(PayWrapper payWrapper) {
        if(null != list){
            for(Pay pay : list) {
                if(!payWrapper.getBizResult().isSuccess()){
                    return;
                }
                if(payWrapper.getPayChannelEnum().equals(pay.getChannel())){
                    pay.pay(payWrapper);
                }
            }
        }
    }

    @Override
    public void payNotify(NotifyWrapper notifyWrapper) {
        if(null != list){
            for(Pay pay : list) {
                if(!notifyWrapper.getBizResult().isSuccess()){
                    return;
                }
                if(notifyWrapper.getPayChannelEnum().equals(pay.getChannel())){
                    pay.payNotify(notifyWrapper);
                }
            }
        }
    }

    @Override
    public PayChannelEnum getChannel() {
        return null;
    }
}
